package com.bridgeintelligent.tag.user.mgmt.service;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import com.bridgeintelligent.tag.user.mgmt.mapper.TagPermMgmtMapper;
import com.bridgeintelligent.tag.user.mgmt.pojo.TagPermission;
import com.wayneleo.quickstart.framework.BaseException;
import com.wayneleo.quickstart.framework.ExceptionCode;
import com.wayneleo.quickstart.framework.IDGenerator;

@Service
public class TagPermMgmtServiceImpl implements TagPermMgmtService {

    private final TagPermMgmtMapper mapper;

    public TagPermMgmtServiceImpl(TagPermMgmtMapper mapper) {
        this.mapper = mapper;
    }

    @Override
    public void add(TagPermission permission) {
        if ( StringUtils.isBlank(permission.getDeptId()) && "01".equals(permission.getType()) ) {
            permission.setDeptId("false");
        }
        if ( StringUtils.isAnyBlank(permission.getRoleId(), permission.getType(), permission.getDeptId()) ) {
            throw new BaseException( new ExceptionCode(999, "角色ID、类型、部门ID 都不能为空"));
        }
        permission.setId(IDGenerator.gen());
        mapper.insert(permission);
    }

    @Override
    public void delete(String roleId) {
        mapper.delete(roleId);
    }

}
